package com.atguigu.activity;

import org.activiti.engine.HistoryService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 网关用来控制流程的流向，通常会和流程变量一起使用。
 */
@SpringBootTest
public class ActivityTest4 {
    @Autowired
    private RepositoryService repositoryService;
    @Autowired
    private RuntimeService runtimeService;
    @Autowired
    private TaskService taskService;
    @Autowired
    private HistoryService historyService;
    /**
     *
     * @author lyj
     * @date 2024-01-14
     * 流程定义部署以及启动
     */
    @Test
    public void deployProcess(){
      /*  Deployment deploy = repositoryService.createDeployment().addClasspathResource("process/qingjia5.bpmn20.xml").name("请假申请流程").deploy();
        System.out.println(deploy.getId());
        System.out.println(deploy.getName());*/
        //key就是act_re_procdef数据表中的key
        Map<String,Object> map=new HashMap<>();
        map.put("day",5);
        runtimeService.startProcessInstanceByKey("qingjia5",map);
    }
    @Test
    public void completGroupTask() {
        Task task = taskService.createTaskQuery()
                .taskAssignee("wangwu")  //要查询的负责人
                .singleResult();//返回一条
        taskService.complete(task.getId());
    }
    /**
     * 查询个人待办任务
     *
     * 查询方式同个人任务查询
     */
    @Test
    public void findGroupPendingTaskList() {
        //任务负责人
        String assignee = "lisi";
        List<Task> list = taskService.createTaskQuery()
                .taskAssignee(assignee)//只查询该任务负责人的任务
                .list();
        for (Task task : list) {
            System.out.println("流程实例id：" + task.getProcessInstanceId());
            System.out.println("任务id：" + task.getId());
            System.out.println("任务负责人：" + task.getAssignee());
            System.out.println("任务名称：" + task.getName());
        }
    }

}
